package com.lin.subject.infra.basic.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.lin.subject.commom.enums.IsDeletedFlagEnum;
import com.lin.subject.infra.basic.entity.SubjectInfo;
import com.lin.subject.infra.basic.service.SubjectInfoService;
import com.lin.subject.infra.basic.mapper.SubjectInfoDao;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
* @author jeremylin
* @description 针对表【subject_info(题目信息表)】的数据库操作Service实现
* @createDate 2024-10-21 11:12:25
*/
@Service
public class SubjectInfoServiceImpl extends ServiceImpl<SubjectInfoDao, SubjectInfo>
    implements SubjectInfoService{


    @Resource
    private SubjectInfoDao subjectInfoDao;

    @Override
    public void insert(SubjectInfo subjectInfo) {
        subjectInfoDao.insert(subjectInfo);
    }

    /**
     * 查询对应题目的总数
     *
     * @param subjectInfo
     * @param categoryId
     * @param labelId
     * @return
     */
    @Override
    public int countByCondition(SubjectInfo subjectInfo, Long categoryId, Long labelId) {
        return this.subjectInfoDao.countByCondition(subjectInfo,categoryId,labelId);
    }

    /**
     * 查询分页
     *
     * @param subjectInfo
     * @param categoryId
     * @param labelId
     * @param start
     * @param pageSize
     * @return
     */
    @Override
    public List<SubjectInfo> queryPage(SubjectInfo subjectInfo, Long categoryId, Long labelId, int start, Integer pageSize) {
        return this.subjectInfoDao.queryPage(subjectInfo,categoryId,labelId,start,pageSize);
    }

    /**
     * 根据题目id，查询题目详情信息
     *
     * @param id
     * @return
     */
    @Override
    public SubjectInfo queryById(Long id) {
        return this.subjectInfoDao.selectById(id);
    }

    @Override
    public int countByCondition2(SubjectInfo subjectInfo, Long categoryId) {
        return this.subjectInfoDao.countByCondition2(subjectInfo,categoryId);
    }

    @Override
    public List<SubjectInfo> queryPage2(SubjectInfo subjectInfo, Long categoryId, int start, Integer pageSize) {
        return this.subjectInfoDao.queryPage2(subjectInfo,categoryId,start,pageSize);
    }

    /**
     * 删除题目
     *
     * @param id
     */
    @Override
    public void removeSubject(Long id) {
        lambdaUpdate().eq(SubjectInfo::getId,id).set(SubjectInfo::getIsDeleted, IsDeletedFlagEnum.DELETED.getCode()).update();;
    }

    @Override
    public List<SubjectInfo> getContributeCount() {
        return this.subjectInfoDao.getContributeCount();
    }

    /**
     * 下一题或上一题的题目id
     * @param subjectId
     * @param categoryId
     * @param labelId
     * @param cursor
     * @return
     */
    @Override
    public Long querySubjectIdCursor(Long subjectId, Long categoryId, Long labelId, int cursor) {
        return this.subjectInfoDao.querySubjectIdCursor(subjectId, categoryId, labelId, cursor);
    }
}




